﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Aesha.WoW.Broker.Model
{
    public class ItemSubClass
    {
        [JsonProperty("subclass")]
        public int ItemSubClassId { get; set; }
        public int ItemClassId { get; set; }
        public string Name { get; set; }

        public ItemClass ItemClass { get; set; }

        public override string ToString()
        {
            return Name;
        }

        public static EntityTypeConfiguration<ItemSubClass> Mapping()
        {
            var m = new EntityTypeConfiguration<ItemSubClass>();

            m.HasKey(t => new {t.ItemSubClassId, t.ItemClassId});
            m.Property(t => t.ItemClassId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
            m.Property(t => t.Name).HasMaxLength(255).IsUnicode(false);

            m.ToTable("ItemSubClass");

            m.HasRequired(t => t.ItemClass)
                .WithMany(t => t.SubClasses)
                .HasForeignKey(t => t.ItemClassId);

            return m;
        }
    }
}
